package icu.lookyousmileface.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author starrysky
 * @title: SingleThreadPool
 * @projectName Juc_Pro
 * @description: 单一线程池
 * @date 2021/1/2910:07 下午
 */
public class SingleThreadPool {
    public static void main(String[] args) {
        //阿里规则使用executors创建线程池，防止资源耗尽
        ExecutorService singlePool = Executors.newSingleThreadExecutor();

        try {
            for (int i = 1; i <= 10; i++) {
                singlePool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"=>ok");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            singlePool.shutdown();
        }

    }
}
